package com.fhcodeintegration.demo06ai.controller;

import com.fhcodeintegration.demo06ai.config.ChatResponse;
import com.fhcodeintegration.demo06ai.service.ZhiPuAIService;
import com.zhipu.oapi.service.v4.model.ChatMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/chat")
@Slf4j // Lombok注解
public class ChatController {
    
    @Autowired
    private ZhiPuAIService zhiPuAIService;

    @PostMapping
    public ChatResponse chat(@RequestBody ChatMessage chatMessage) {

        String aiResponse = zhiPuAIService.doChat(chatMessage);

        // 这里假设没有会话 ID，如果有，可以从 `chatMessage` 或 `aiResponse` 获取
        ChatResponse response = new ChatResponse(200,aiResponse, null);

        return response;
    }
}